package com.swyc.osschat.Test.StreamTest.Controller;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import com.google.common.collect.ImmutableList;
import com.swyc.osschat.Test.LambdaTest.Bean.Student;
import com.swyc.osschat.Test.StreamTest.Bean.SpecialityEnum;

/**
 * @author zhaol@yunrong.cn
 * @version V2.1
 * @since 2.1.0 2019/8/9 16:51
 */
public class TestCaseThree {
    public static void main(String[] args) {
        List<Student> students = Student.generateData();
        //todo 转换成块(根据属性对集合分块)
        Map<Boolean, List<Student>> listMap = students.stream().collect(
            Collectors.partitioningBy(student ->
                student.getSpecialityEnums().
                    contains(SpecialityEnum.SING)));
        //todo 根据集合中的对象的某一个属性对集合进行分组
        Map<SpecialityEnum, List<Student>> listMap2 =
            students.stream().collect(
                Collectors.groupingBy(student -> student.getSpecialityEnums().get(0)));
        //todo 拼接字符串
        String names = students.stream()
            .map(Student::getName).collect(Collectors.joining(",","[","]"));
        System.out.println(listMap);
    }
}
